package fy.erp.manager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.json.JSONArray;
import org.json.JSONObject;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class KeMuDuanFileReader {

	private InputStream inputStream;

	private String result;

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getResult() {
		return result;
	}

	public void read() {
		try {
			Workbook book = Workbook.getWorkbook(new File("D:/imp.xls"));

			Sheet sheet = book.getSheet(0);

			int length = sheet.getRows();
			
			JSONArray ja = new JSONArray();
			for(int i = 1; i < length; i++){
				Cell[] row = sheet.getRow(i);
				if (row.length >= 4 && fy.util.MyUtil.strIsNotNull(row[0].getContents()) ) {
					JSONObject jo = new JSONObject();
					jo.put("company", row[0].getContents());
					jo.put("subject", row[1].getContents());
					jo.put("number", row[2].getContents());
					jo.put("description", row[3].getContents());
					ja.put(jo);
				}else{
					break;
				}
			}

			result = ja.toString();
			book.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	public static void main(String[] args) {
		KeMuDuanFileReader r = new KeMuDuanFileReader();
		r.read();
	}
}
